package com.limh.base.base

import android.os.Bundle
import android.support.v4.app.Fragment
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.limh.base.utils.Logs

/**
 * @author limh
 * @function
 * @date 2018/4/18 10:51
 */
abstract class BaseFragment : Fragment() {
    var TAG = "BaseFragment"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Logs.w("onCreate")
        TAG = this.javaClass.simpleName
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        Logs.w("onCreateView")
        return inflater.inflate(getLayoutId(), null)
    }

    abstract fun getLayoutId(): Int

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Logs.w("onViewCreated")
        initViews(view)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        Logs.w("onActivityCreated")
        initDatas()
    }

    abstract fun initViews(view: View)

    abstract fun initDatas()

    fun showToast(msg: String) {
        if (!TextUtils.isEmpty(msg)) {
            Toast.makeText(context!!.applicationContext, msg, Toast.LENGTH_SHORT).show()
        }

    }
}
